<?php
// +----------------------------------------------------------------------
// | Diygw PHP
// +----------------------------------------------------------------------
// | Copyright (c) 2022~2025 https://www.diygw.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: diygw <diygwcom@diygw.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\cms\model;

use diygw\model\DiygwModel;

/**
 * @package app\cms\model
 */
class HuodongDataModel extends DiygwModel
{
    // 表名
    public $name = 'cms_huodong_data';

    // 相似查询字段
    protected $likeField=[];

    public function beforeAdd(&$data)
    {
        $huodongDataModel = new HuodongDataModel();
        $count = $huodongDataModel->where('huodong_id',$data['huodongId'])->where('user_id',\request()->userId)->count();
        if($count>0){
            $this->error="已报名，不能重复报名";
            return false;
        }
        return true;
    }

    public function afterAdd(&$data)
    {
        $huodongDataModel = new HuodongDataModel();
        $count = $huodongDataModel->where('huodong_id',$data['huodongId'])->count();
        $huodongModel = new HuodongModel();
        $huodongModel->where('id',$data['huodongId'])->update(['baomingnum'=>$count]);
        return true;
    }
}
